package com.mezz.bones.user.application.executor.cmd.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mezz.bones.user.application.domain.cmd.SysRoleCreateCmd;
import com.mezz.bones.user.application.domain.cmd.SysRoleDeleteCmd;
import com.mezz.bones.user.application.domain.cmd.SysRoleUpdateCmd;
import com.mezz.bones.user.application.domain.qry.SysRolePageForAppQry;
import com.mezz.bones.user.application.domain.res.SysRoleDetailForAppResponse;
import com.mezz.bones.user.application.domain.res.SysRolePageForAppResponse;
import com.mezz.bones.user.application.executor.cmd.ISysRoleExecutor;
import com.mezz.bones.user.application.repository.ISysRoleRepository;
import com.mezz.bones.user.client.domain.entity.SysRole;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @Author: zhuang
 * @Date: 2025/7/14 14:25
 * @Description: TODO
 * @Version: 1.0
 **/

@Service
@Slf4j
@AllArgsConstructor
public class SysRoleExecutorImpl implements ISysRoleExecutor {

    private final ISysRoleRepository sysRoleRepository;

    @Override
    public void execSysRoleCreateCmd(SysRoleCreateCmd cmd) {
        SysRole add = new SysRole();
        BeanUtils.copyProperties(cmd, add);
        sysRoleRepository.save(add);
    }

    @Override
    public void execSysRoleUpdateCmd(SysRoleUpdateCmd cmd) {
        SysRole update = new SysRole();
        BeanUtils.copyProperties(cmd, update);
        sysRoleRepository.updateById(update);
    }

    @Override
    public void execSysRoleDeleteCmd(SysRoleDeleteCmd cmd) {
        SysRole delete = new SysRole();
        delete.setId(cmd.getId());
        delete.setUpdateBy(cmd.getOperatorId());
        delete.setUpdateName(cmd.getOperatorName());
        delete.setUpdateTime(cmd.getOperatorTime());
        sysRoleRepository.updateById(delete);
    }

    @Override
    public SysRoleDetailForAppResponse detailForApp(String id) {
        SysRole sysRole = sysRoleRepository.getByIdWithException(id);
        SysRoleDetailForAppResponse res = new SysRoleDetailForAppResponse();
        BeanUtils.copyProperties(sysRole, res);
        return res;
    }

    @Override
    public Page<SysRolePageForAppResponse> pageForApp(SysRolePageForAppQry qry) {
        return null;
    }

}
